/*
 * Copyright 2007 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.rtp.transformer.fin.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FormHandler;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FormSubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormSubmitEvent;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Demonstrates the various button widgets.
 */
public class ReportUpload extends Sink {

	public static SinkInfo init(final Sink.Images images) {
		return new SinkInfo(
				"Uploads",
				"<h2>Upload function</h2>"
						+ "<p>Gao Wen can upload the General Ledger Report by this interface. "
						+ "</p><p>The data will be kept into fin database as report data source. "
						+ "</p>") {

			public Sink createInstance() {
				return new ReportUpload(images);
			}
 
		};
	}

	private VerticalPanel panel = new VerticalPanel();

	public ReportUpload(Sink.Images images) {
		 

		final FormPanel formPanel = new FormPanel();
		formPanel.setAction("Upload");
		panel.add(formPanel);
		formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
		formPanel.setMethod(FormPanel.METHOD_POST);
		 
        FlowPanel formWidget = new FlowPanel();
        formPanel.setWidget(formWidget);
        
		final FileUpload fileUpload = new FileUpload();
		fileUpload.setName("file");
		formWidget.add(fileUpload);
		 
		panel.setSpacing(8);
		initWidget(panel);
		formPanel.addFormHandler(new FormHandler(){

			public void onSubmit(FormSubmitEvent event) {
				// TODO Auto-generated method stub
//				Window.alert(event.toString());
			}

			public void onSubmitComplete(FormSubmitCompleteEvent event) {
				// TODO Auto-generated method stub
				Window.alert("the document is uploaded!");
			}
			
		});
		
		final Button submitButton = new Button("Submit",new ClickListener(){

			public void onClick(Widget sender) {
				// TODO Auto-generated method stub
				formPanel.submit();
			}			
		});
		panel.add(submitButton);
	}

	public void onShow() {
	}

}
